package com.lgq.cfw.controller.permission;

import com.lgq.cfw.bean.message.Message;
import com.lgq.cfw.service.AccountTypeAndCertService;
import com.lgq.cfw.service.CertService;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Lin
 * @date 2019-02-12 15:55
 **/
@RestController
@RequestMapping(value = "/permission/accountTypeAndCert")
public class AccountTypeAndCertController {

  @Autowired
  AccountTypeAndCertService accountTypeAndCertService;
  @Autowired
  CertService certService;

  @RequestMapping(value = "/get",method = RequestMethod.GET)
  public Message getAccountTypeAndCert(){

    return Message.success("处理成功",null)
        .add("cert",certService.getAllCert()).add("accountTypeAndCert",accountTypeAndCertService.getAccountTypeAndCert());
  }

  @RequestMapping(value = "/update",method = RequestMethod.POST)
  public Message updateAccountTypeAndCert(@RequestParam(value = "updateString")String updateString){
    boolean flag=accountTypeAndCertService.deleteAll();
    try {
      accountTypeAndCertService.updateAccountTypeAndCert(updateString);
    }catch (Exception e){
      e.printStackTrace();
      flag=false;
    }
    if (flag){
      return Message.success("处理成功",null);
    }else {
      return Message.fail("处理失败",null);
    }
  }


}
